package logic

import (
	"context"
	"house_srv/model/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *house.ListRequest) (*house.ListResponse, error) {
	// todo: add your logic here and delete this line
	var houses []mysql.House
	mysql.DB.Debug().Find(&houses)
	var allhouse []*house.HouseList
	for _, m := range houses {
		list := house.HouseList{
			Address: m.Address,
			Size:    m.Size,
			Price:   float32(m.Price),
			Name:    m.Name,
			Image:   m.Image,
			Id:      int64(m.ID),
		}
		allhouse = append(allhouse, &list)
	}
	return &house.ListResponse{
		List: allhouse,
	}, nil
}
